import { http } from "@/utils/http";
import {
  GetUserInfoModel,
  LoginParams,
  OauthTokenModel,
} from "./model/oauthModel";

enum Api {
  Login = "/oauth/password/login",
  CodeLogin = "/oauth/code/login",
  Logout = "/oauth/logout",
  GetUserInfo = "/oauth/userInfo",
}

/** 登录 */
export function doLogin(params: LoginParams) {
  return http.post<OauthTokenModel>({
    url: Api.Login,
    params,
  });
}

export function getUserInfo() {
  return http.post<GetUserInfoModel>({
    url: Api.GetUserInfo,
  });
}

export function doLogout(accessToken?: string) {
  return http.post({
    url: Api.Logout,
    params: {
      accessToken: accessToken,
    },
  });
}
